<?php

namespace app\common\model;

use Think\Db;

/**
 * 等级类别管理
 */
class Levels extends Base
{

    /**
     * 获取等级类别信息
     */
    public function getById($val,$field='id') {
        return (Object) $this->where($field, $val)->find()->toArray();
    }

    /**
     * 根据会员等级level获取会员名称
     */
    public function getByNmane($level)
    {
        return (Object) $this->where('level', $level)->find()->toArray();
    }
    /**
     * 获取等级类别列表
     * @param type $where
     * @return type
     */
    public function getAll($where = null)
    {
        return $this->where($where)->order('id', 'asc')->select()->toArray();
    }

    /**
     * 删除等级类别
     */
    public function del()
    {
        $id     = input('id');
        $result = $this->where("id={$id} or id={$id}")->delete();
        if (false !== $result)
        {
            return [1, "删除成功:" . input('id')];
        }
        else
        {
            return [0, $this->getError()];
        }
    }

    /**
     * 获取josn用到的列表
     */
    public function getLevelsList($type)
    {

        $page  = input('get.page');
        $limit = input('get.limit');
        $where = '1=1';
        if ($type == 1) {//分页
            return $this->where($where)->page($page, $limit)->select()->toArray();
        } else {//总数
            return $this->where($where)->select()->toArray();
        }
    }
    
    public function get_fan_dian()
    {
        $one = [];
        $two = [];
        $list = $this->getAll("level !=1");
        foreach ($list as $k=>$v)
        {
            $one +=[$v['level']=>$v['firstonescale']];
            $two +=[$v['level']=>$v['onescale']];
        }
        return $arr = [0=>$one,1=>$two];
    }

}
